<include file="public@header"/>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('record/index')}">积分记录列表</a></li>
        <li class="active"><a>编辑积分记录</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('record/editPost')}">
        <div class="form-group">
            <label class="col-sm-2 control-label">所属学校<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10" >
                <select class="form-control" name="" id="selectSchool" >
                    <option value="0">|--请选择学校--|</option>
                    <foreach name="school" item="vo">
                        <if $school_id == $vo.id>
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else>
                                <option value="{$vo.id}">{$vo.name}</option>
                            </else>
                        </if>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">所属班级<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10" >
                <select  id="selectRoom" class="form-control">
                    <foreach name="room" item="vo">
                        <if $room_id == $vo.id>
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else>
                                <option value="{$vo.id}">{$vo.name}</option>
                            </else>
                        </if>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">学生<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10" >
                <select name="student_id" id="student_id" class="form-control">
                    <option value="">|--请选择学生--|</option>
                    <foreach name="student" item="vo">
                        <if $data.student_id == $vo.id>
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else>
                                <option value="{$vo.id}">{$vo.name}</option>
                            </else>
                        </if>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">原因<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10" >
                <select name="reason_id" id="reason_id" class="form-control">
                    <option value="">|--请选择原因--|</option>
                    <foreach name="reason" item="vo">
                        <if $data.reason_id == $vo.id>
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else>
                                <option value="{$vo.id}">{$vo.name}</option>
                            </else>
                        </if>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">积分<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10" >
                <select name="score_id" id="score_id" class="form-control">
                    <option value="">|--请选择积分--|</option>
                    <foreach name="score" item="vo">
                        <if $data.score_id == $vo.id>
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else>
                                <option value="{$vo.id}">{$vo.name}</option>
                            </else>
                        </if>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="hidden" name="id" value="{$data.id}">
                <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                <a class="btn btn-default" href="{:url('record/index')}">{:lang('BACK')}</a>
            </div>
        </div>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/layui/layui.all.js"></script>
<script>
    //使用ajax将所选的文件异步发送给php导入方法
    layui.use('upload',function () {
        var upload = layui.upload;
        var uploadInst = upload .render({
            elem:"#selectPicture",
            url:"{:url('record/upload')}",
            field:'picture',
            done:function (res) {
                if (res.code == 200){
                    layer.msg(res.msg);
                    $('#prew').attr('src',res.path);
                    $('#pic_path').val(res.path);
                } else {
                    layer.msg(res.msg);
                }
            }
        });
    })
</script>
<script>
    $(function () {
        $('#selectSchool').change('click',function () {
            var schoolId=$('#selectSchool').val();
            $.ajax({
                url:"{:url('record/getRoomBySchool')}",
                type:"POST",
                data:{school_id:schoolId},
                success:function (res) {
                    console.log(res);
                    $('#selectRoom').html(res);
                }
            })
        })
    })
    $(function () {
        $('#selectRoom').change('click',function () {
            var roomId=$('#selectRoom').val();
            $.ajax({
                url:"{:url('record/getStudentByRoom')}",
                type:"POST",
                data:{room_id:roomId},
                success:function (res) {
                    console.log(res);
                    $('#student_id').html(res);
                }
            })
        })
    })
</script>
</body>
</html>